package com.client.mapper;

import com.Emplyment.entity.Article;
import com.Emplyment.entity.UserRegister;
import com.Emplyment.vo.ClientUserInfosVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ClientUserMapper {



    //todo：以后要优化的话可以把select语句写进xml里面用动态语句的方式，只是多了一个密码而已

    /**
     * 查询是否有客户端的用户资料
     * @param usernames
     * @return
     */
    @Select("select * from client_user where username = #{username}")
    UserRegister clientuser(String usernames);

    /**
     * 将注册账号密码添加进数据库
     * @param user
     */
    @Insert("insert into client_user(username, password, create_time,email) VALUES (#{username}, #{password}, #{createTime}, #{email})")
    void insertUser(UserRegister user);

    /**
     * 登录查询数据库验证信息
     * @param username
     * @param password
     * @return
     */
    @Select("select * from client_user where username = #{username} and password = #{password}")
    UserRegister clientuserlogin(String username, String password);

    /**
     * 根据用户id查询用户信息
     * @param userId
     * @return
     * **/
    @Select("select id,username,nickname,email,userPic from client_user where id = #{userId}")
    ClientUserInfosVo getUserInfo(Long userId);

    /**
     * 查询公司信息
     */
    @Select("select * from article where id = #{empId}")
    Article getCompany(Integer empId);

    @Select("select count(id) from client_user where email = #{email}")
    Integer clientuseremail(String email);

    @Update("update client_user set password = #{newPassword} where email = #{email}")
    void updatePassword(String email, String newPassword);

    @Select("select * from client_user where email = #{username} and password = #{password}")
    UserRegister clientemaillogin(String username, String password);
}
